//
//  XCVisitorView.swift
//  小陈微博Swift用纯代码创建
//
//  Created by 小陈 on 16/2/26.
//  Copyright © 2016年 小陈. All rights reserved.
//

import UIKit

///  访客登录视图协议
protocol VisitorLoginViewDelegate:NSObjectProtocol{
    ///  选中注册按钮
    func didSelectResgisterButton()
    /// 选中登录按钮
    func didSelectedLonginButton()
}

class XCVisitorView: UIView {
    weak var vistorViewDelegate : VisitorLoginViewDelegate?
    
    /// 首页和消息、发现、我 的图片
    @IBOutlet weak var IconView: UIImageView!
    /// 圆形的图片
    @IBOutlet weak var SmallIcon: UIImageView!
    @IBOutlet weak var MessageLable: UILabel!
    
    
    func setUpInfo(imageName:String,message:String,isHome:Bool = false ){
        IconView.hidden = !isHome
        if isHome {
            IconView.image = UIImage(named: imageName)
            SmallIcon.image = UIImage(named: "visitordiscover_feed_image_smallicon")
        }else{
            SmallIcon.image = UIImage(named: imageName)
        }
        MessageLable.text = message
        

         isHome ? startAnimation() : stopAnimation()
    }
    
    
    func startAnimation (){
        //MARK: - 执行图片的转动操作
        let anim  = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = 2 * M_PI
        anim.repeatCount = MAXFLOAT
        anim.duration = 20.0
        /// 
        anim.removedOnCompletion = false
        SmallIcon.layer.addAnimation(anim, forKey: nil)
    }
    func stopAnimation(){
        SmallIcon.layer.removeAllAnimations()
    }
    
    
   //MARK: - 注册按钮
    @IBAction func Registe() {
        vistorViewDelegate?.didSelectResgisterButton()
//        let networkingTool = XCNetworkingTool.sharedInstance
       
    }
   //MARK: 登录按钮
    @IBAction func Login() {
        vistorViewDelegate?.didSelectedLonginButton()
    }
}
